package com.ch.clinking;

import android.annotation.SuppressLint;
import android.app.Application;
import android.icu.util.Calendar;
import android.os.Build;
import android.util.Log;

import androidx.annotation.RequiresApi;
import androidx.room.Room;

import com.ch.clinking.bean.Shop;
import com.ch.clinking.bean.User;
import com.ch.clinking.database.ClinkingDatabase;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.TimeZone;

public class ClinkingApplication extends Application {

    private static ClinkingApplication application;
    public List<Shop> shopList;
    public Integer shopPosition = 0;
    public User user;
    public List<String> onlineMembers = new ArrayList<>();
    public boolean firstLogin = true;
    public boolean flashFlag;
    private ClinkingDatabase database;
    public int productionCycle = 11;
    public int replenishDay = 5;

    public static ClinkingApplication getInstance() {
        return application;
    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    public void onCreate() {
        super.onCreate();
        database = Room.databaseBuilder(this, ClinkingDatabase.class, "clink")
                .addMigrations()
                .allowMainThreadQueries()
                .build();
        application = this;
        // 获取当前时间的 Calendar 实例
        Calendar calendar = Calendar.getInstance();

        // 获取当前日期和时间
        Date currentDate = calendar.getTime();

        TimeZone defaultTimeZone = TimeZone.getDefault();

        Log.d("TimeZone", defaultTimeZone.getID()+currentDate);

        // 定义日期格式
        @SuppressLint("SimpleDateFormat") SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        // 使用默认时区格式化日期
        dateFormat.setTimeZone(defaultTimeZone);

        // 使用 format 方法将 Date 转换为字符串
        String formattedDate = dateFormat.format(currentDate);

        Log.d("TimeZone", "formattedDate"+formattedDate);
    }

    public ClinkingDatabase getDatabase() {
        return database;
    }

}
